//
//  SetViewController.m
//  BGM
//
//  Created by liuqin on 2018/11/28.
//  Copyright © 2018年 com.alirtc.demo. All rights reserved.
//

#import "SetViewController.h"
#import "Common.h"
#import "MeTableViewCell.h"
#import "BGMHTTP.h"
#import "BGMUser.h"

#import "LoginViewController.h"

#import "SetChatViewController.h"
#import "SetAccViewController.h"
#import "SetProposalViewController.h"
#import "SetSrecyViewController.h"
@interface SetViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)NSArray *messageArray;

@end

@implementation SetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navview.hidden = NO;
    self.titleBtn.hidden = NO;
    [self.titleBtn setTitle:@"设置" forState:UIControlStateNormal];
    self.messageArray = @[@"通知与聊天",@"账号与安全",@"反馈与建议",@"隐私设置",@"清除缓存"];
    UITableView *myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, self.navview.frame.size.height, SCREENW, SCREENH-self.navview.frame.size.height)];
    myTableView.backgroundColor = [UIColor clearColor];
    myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    myTableView.delegate = self;
    myTableView.dataSource = self;
    myTableView.scrollEnabled = NO;
    [self.view addSubview:myTableView];
    
    
    UIButton *logoutBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREENW-30, 50)];
    logoutBtn.backgroundColor =bgmColor(244, 244, 244);
    logoutBtn.center = CGPointMake(SCREENW/2, SCREENH-90);
    [self.view addSubview:logoutBtn];
    logoutBtn.layer.cornerRadius = 8;
    logoutBtn.layer.masksToBounds = YES;
    [logoutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    [logoutBtn setTitleColor:bgmmainColor forState:UIControlStateNormal];
    [logoutBtn addTarget:self action:@selector(clickLogOut) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, SCREENH-30, SCREENW, 20)];
    label.text = @"素友 1.1.0";
    label.font = [UIFont systemFontOfSize:13];
    label.textColor = bgmColor(155, 155, 155);
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
    
}
#pragma mark UITABLEVIEWDELEAGE
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"MeTableViewCell";
    MeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[MeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.iconBtn.hidden = NO;
        cell.contentLabel.frame = CGRectMake(15, 0, 300, 50);
        cell.line.frame = CGRectMake(15, 50-0.3, SCREENW, 0.3);
    }
    cell.contentLabel.text =[self.messageArray objectAtIndex:indexPath.row];
    

    if (indexPath.row==4){
        cell.rightLabel.hidden = NO;
        cell.rightLabel.text = @"43M";
        cell.rightLabel.textColor = bgmgrayColor;
        cell.rightLabel.font = [UIFont systemFontOfSize:13];
        cell.rightLabel.frame =CGRectMake(120, 0, SCREENW-160, 50);

    }else{
        cell.rightLabel.hidden = YES;
    }

    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    int i = (int)indexPath.row;
    switch (i) {
        case 0:
        {
            SetChatViewController *vc = [[SetChatViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            SetAccViewController *vc = [[SetAccViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            SetProposalViewController *vc = [[SetProposalViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:
        {
             SetSrecyViewController *vc = [[SetSrecyViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}


#pragma mark 退出登录
- (void)clickLogOut{
    NSLog(@"asdfsdaf");
    BGMUser *user = [BGMUser shareInstance];
    user = nil;
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    [ud removeObjectForKey:@"ISLOGINKEY"];
//    NSString *token = user.userToken;
//    //    __weak typeof(self)
//    [BGMHTTP requestWithMethodName:@"login/returnLogin" parameters:@{@"userToken":token} completion:^(BOOL success, NSError *error, NSDictionary *result) {
        [self gotoLoginVC];
//    }];

}

- (void)gotoLoginVC{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"gotoLoginVC" object:nil];
}

@end
